package com.example.wxai.controller;


import com.example.wxai.pijo.dto.MyInfoDto;
import com.example.wxai.pijo.dto.UserDto;
import com.example.wxai.pijo.entity.User;
import com.example.wxai.pijo.vo.HandUpVo;
import com.example.wxai.pijo.vo.UserVo;
import com.example.wxai.result.PageResult;
import com.example.wxai.result.Result;
import com.example.wxai.service.impl.EssayServiceImpl;
import com.example.wxai.service.impl.UserServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-12
 */
@Slf4j
@RestController
@RequestMapping("/user")

public class UserController {
    @Resource
    private UserServiceImpl userService;

    @Resource
    private EssayServiceImpl essayService;

    @PostMapping("/login")
    public Result<User> Login(@RequestBody UserDto userDto){

        log.info("登录{}",userDto);
        User one=userService.lambdaQuery().eq(User::getUserId,userDto.getUserId())
                .eq(User::getUserPassword,userDto.getUserPassword()).one();
        if(one!=null){
            Map<String,String> map=new HashMap<>();
            map.put("username",userDto.getUserId());
            return Result.success(one);
        }
        return Result.error("账号或密码错误");
    }

    @GetMapping("/getUser")
    public Result<User> getUser( String userId){
        log.info("查询用户{}",userId);
        User one = userService.lambdaQuery().eq(User::getUserId, userId).one();
        if(one==null){
            return Result.error("未查询要用户");
        }
        return Result.success(one);
    }



    @PostMapping("/getMyInfo")
    public PageResult<HandUpVo> getEssayList(@RequestBody MyInfoDto myInfoDto){
        log.info("我的帖子/点赞/评论查询{}",myInfoDto.getInfo());
        PageResult<HandUpVo> pageResult=essayService.queryINfoPage(myInfoDto);
        return pageResult;
    }


   @PostMapping("/getPageUser")
    public PageResult<UserVo> pageList(@RequestBody UserDto userDto){
        log.info("条件查询用户信息{}",userDto);
        PageResult<UserVo> userVoPageResult=userService.pageList(userDto);
        return userVoPageResult;
   }

}
